<template>
    <div class="base_form">
      <div class="base_header">
        <div class="blue_column"></div>
        <div class="base_title">荣誉信息</div>
      </div>
      <div class="form-div" style="margin-top: 5px">
        <table class="content">
          
          <tr>
            <td colspan="1" style="text-align: right">荣誉序号</td>
            <td colspan="1"><input v-model="form.honourId" style="width: 97%" /></td>
          </tr>
          <tr>
            <td colspan="1" style="text-align: right">序号</td>
            <td colspan="1"><input v-model="form.number" style="width: 97%" /></td>
          </tr>
          <tr>
            <td colspan="1" style="text-align: right">学号</td>
            <td colspan="1"><input v-model="form.num" style="width: 97%" /></td>
          </tr>
          <tr>
            <td colspan="1" style="text-align: right">姓名</td>
            <td colspan="1"><input v-model="form.name" style="width: 97%" /></td>
          </tr>
          <tr>
            <td colspan="1" style="text-align: right">奖项</td>
            <td colspan="1">
              <input v-model="form.honourName" style="width: 97%" />
            </td>
          </tr>
          <tr>
            <td colspan="1" style="text-align: right">奖项描述</td>
            <td colspan="1"><input v-model="form.describe" style="width: 97%" /></td>
          </tr>
          <tr>
            <td colspan="2">
              <button class="commButton" @click="submit">提交</button>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </template>
  <script lang="ts">
  import { getDictionaryOptionItemList } from "~/services/systemServ";
  import { getHonourInfo, honourEditSave } from "~/services/personServ";
  import { defineComponent } from "vue";
  import router from "~/router";
  import { type OptionItem, type HonourItem } from "~/models/general";
  import { getOptionItem } from "~/tools/comMethod";
  import { formatDate } from "~/tools/comMethod";
  
  export default defineComponent({
    //数据
    data: () => ({
      valid: false,
      honourId: null as number | null,
      form: {} as HonourItem,
      birthday: new Date(),
      gender: {} as OptionItem,
      genderList: [] as OptionItem[],
      nameRules: [],
      emailRules: [],
    }),
    //页面加载方法, 获取性别选择列表,获取学生信息,注意async和await的使用
    async created() {
      //获取获取路由参数,上一个页面传过来的学生id
      const res = this.$route.query.honourId;
      if (res != null) {
        this.honourId = parseInt(res.toString());
      }
      this.genderList = await getDictionaryOptionItemList("XBM");
      if (this.honourId != null) {
        this.form = await getHonourInfo(this.honourId);
      }
    },
    methods: {
      //提交表单
      async submit() {
        //      this.form.gender = this.gender.value;
        const res = await honourEditSave(this.form);
        if (res.code == 0) {
          router.push({ path: "/honour-panel" });
        } else {
          alert(res.msg);
        }
      },
    },
  });
  </script>
  